<template>
  <div class="popup" v-if="popupVisible">
    <transition name="fade">
      <!-- click.stop.prevent禁止事件冒泡 -->
      <div class="popup-bg" @click.stop.prevent="hide" v-show="popupVisible"></div>
    </transition>
    <transition name="popup-slide-up">
      <div class="popup-wrapper" v-show="visible">
        <div class="popup-title" v-if="title && title.length > 0">{{title}}</div>
        <div class="popup-btn"
            :class="{'danger': item.type === 'danger'}"
            v-for="(item, index) in btn"
            :key="index"
            @click="item.click">{{item.text}}</div>
      </div>
    </transition>
  </div>
</template>

<script>
  export default {
    name: 'popup',
    props: {
      title: String,
      btn: Array
    },
    data() {
      return {
        // 按钮跟背景隐藏有一个顺序
        // 背景
        popupVisible: false,
        // 按钮
        visible: false
      }
    },
    methods: {
      show() {
        this.popupVisible = true
        setTimeout(() => {
          this.visible = true
        })
      },
      hide() {
        this.visible = false
        setTimeout(() => {
          this.popupVisible = false
        }, 200)
      }
    }
  }
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
  @import "../../assets/styles/global";
  .popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .4);
    .popup-bg{
      width: 100%;
      height: 100%;
    }
    .popup-wrapper{
      position: fixed;
      left: 0;
      bottom: 0;
      z-index: 1000;
      width: 100%;
      background: white;
      .popup-title{
        width: 100%;
        height: px2rem(90);// 44
        border-bottom: px2rem(2) solid #eee;//1
        font-size: px2rem(24);//12
        line-height: px2rem(38);//14
        padding: px2rem(20);//15
        box-sizing: border-box;
        color: #999;
        @include center
      }
      .popup-btn{
        width: 100%;
        height: px2rem(120);//60
        border-bottom: px2rem(2) solid #eee;
        font-size: px2rem(32);//16
        color: #666;
        font-weight: bold;
        @include center;
        &.danger{
          color: $color-pink;
        }
      }
    }
  }
</style>
